﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter09.Code01.Code03.Example01
{
    public class MyClass
    {
        public readonly string Name;
        private int intVal;

        private MyClass()
            : this("Default Name")
        {

        }

        public MyClass(string newName)
        {
            Name = newName;
            intVal = 0;
        }

        public int IntVal
        {
            get
            {
                return intVal;
            }
            set
            {
                if (value >= 0 && value <= 10)
                {
                    intVal = value;
                }
                else
                {
                    throw (new ArgumentOutOfRangeException("Val", value, "Val must be assiged a value between o and 10."));
                }
            }
        }

        public override string ToString()
        {
            return "Name: " + Name + "\nVal: " + IntVal;
        }
    }
}
